package com.orilore.gb.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.orilore.dto.XEployeeDto;
import com.orilore.gb.biz.XDepartBiz;
import com.orilore.gb.biz.XEmployeeBiz;
import com.orilore.gb.entity.XDepart;

/**
 * Servlet implementation class QueryEmployeePageServlet
 */
public class QueryEmployeePageServlet extends HttpServlet implements Servlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public QueryEmployeePageServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	// request.setCharacterEncoding("UTF-8");
		 
		 
		 String curpage = request.getParameter("curpage");
		 
		 
		 String name = request.getParameter("name");
		 
		 if(name!=null) {
		 
		 name = new String(name.getBytes("ISO-8859-1"),"UTF-8");
		 
		 }
		 
		 String beginage = request.getParameter("beginage");
		 
		 String endage = request.getParameter("endage");
		 
		 String sex = request.getParameter("sex");
		 
		 String did = request.getParameter("did");
		 
		 String address = request.getParameter("address");
		 
		 if(address!=null) {
			 
			 
			 address = new String(address.getBytes("ISO-8859-1"),"UTF-8");
			 
			 
		 }
		 
	
		 XEmployeeBiz  biz1 = new XEmployeeBiz();
		 
		 XDepartBiz  biz2 = new XDepartBiz();
		 
		 
		List<XEployeeDto> list = biz1.queryPage(name, sex, beginage, endage, address, did, Integer.parseInt(curpage));
		 
		List<XDepart>  dlist = biz2.findAllXDepart();
		
		
		int pagecounts = biz1.getpages(name, sex, beginage, endage, address, did);
		 
		 
		request.setAttribute("list", list);
		
		request.setAttribute("dlist", dlist);
		
		request.setAttribute("counts", pagecounts);
		
		
		request.setAttribute("name", name);
		
		request.setAttribute("beginage", beginage);
		
		request.setAttribute("endage", endage);
		
		request.setAttribute("sex", Integer.parseInt(sex));
		
		request.setAttribute("did", Integer.parseInt(did));
		
		request.setAttribute("address", address);
		
		
		request.setAttribute("curpage", curpage);
		
		
		request.getRequestDispatcher("ViewEmployee.jsp").forward(request, response);
		
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
